package com.agent.platform.mq;

import com.agent.platform.config.RabbitMQConfig;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

/**
 * 任务消息生产者
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class TaskProducer {
    
    private final RabbitTemplate rabbitTemplate;
    
    /**
     * 发送任务消息
     */
    public void sendTask(TaskMessage message) {
        try {
            rabbitTemplate.convertAndSend(
                    RabbitMQConfig.TASK_EXCHANGE,
                    RabbitMQConfig.TASK_ROUTING_KEY,
                    message
            );
            log.info("任务消息已发送: taskId={}, taskType={}", 
                    message.getTaskId(), message.getTaskType());
        } catch (Exception e) {
            log.error("发送任务消息失败: taskId={}", message.getTaskId(), e);
            throw new RuntimeException("发送任务消息失败", e);
        }
    }
}
